package com.fingard.dsp.bank.directbank.hsbc01;

import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.ITransaction;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7515TodayTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.RetAtsTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.detail.RetAtsTransDetail;
import com.fingard.io.FileHelper;

/**
 * @author XueJy on 2018/9/14.
 * @version 1.0
 */
public class HSBC01Transaction extends HSBC01Base implements ITransaction {
    DecimalFormat df = new DecimalFormat("0.00");

    @Override
    public RetAtsTrans d_7516_HisTrans(Req7516HisTrans p_req7516) throws Exception {
        RetAtsTrans retAts = new RetAtsTrans(p_req7516.reqHeader);
        retAts.writeStart();//写返回ATS的统一头部信息
        if("0".equals(this.getBankConfig().getValueAsString("channelFalg"))){
            String actNum = p_req7516.actNum;
            try {
                //账号地区区域码
                String actArea = p_req7516.actArea;
                //查询起止时间
                Calendar calendarFrom = Calendar.getInstance();
                calendarFrom.setTime(p_req7516.getDateFrom());
                Calendar calendarTo = Calendar.getInstance();
                calendarTo.setTime(p_req7516.getDateTo());
                //超出当前时间则使用当前 时间
                if (calendarTo.getTime().getTime() > System.currentTimeMillis()) {
                    calendarTo.setTime(new Date());
                }
                //List<String[]> prebalances = new ArrayList<>();
                //存放历时余额详情Map Key为日期yyyy-MM-dd ,Value为当日余额
                int numOfDate = calendarTo.get(Calendar.DAY_OF_YEAR) - calendarFrom.get(Calendar.DAY_OF_YEAR) + 1;
//                Map<String, String> hisTransactionMap = new HashMap<String, String>(numOfDate);
                List<String> list = new ArrayList<String>();
                for (int x = 0; x < numOfDate; x++) {
                    //key :yyyyMMdd  value String[]
                    list.add(Format.Date8Format.format(calendarFrom.getTime()));
                    calendarFrom.add(Calendar.DAY_OF_MONTH, 1);
                }
                downloadFile();
                //读取
                for (String history : list) {
                    //指定日期路径
                    String fileDatePath = getReceivePath(EnumDirType.MT940.getValue(), Format.Date8Format.parse(history.substring(0, 6) + history.substring(6, 8)));
                    List<String> fileNames = getDirectoryAllFileName(fileDatePath);
                    String aimFile = "";
                    //STMTCN.EJ321.091904534678.088251418012.TXT
                    for (String filename : fileNames) {
                        String[] filesplit = filename.split("\\.");
                        if (filesplit.length > 3) {
                            if (filesplit[3].equals(actNum)) {
                                aimFile = filename;
                                break;
                            }
                        }
                    }
                    try {
                        //如果无文件则跳过
                        if ("".equals(aimFile)) {
                            continue;
                        }
                        String alltext = "";
                        synchronized (this) {
                            //读取文件内容
                            alltext = FileHelper.readFileText(fileDatePath + File.separator + aimFile, getCharset());
                        }
                        //对单个文件进行解析查找对应的账号明细信息 //:25: 跟账号
                        String[] sArray1 = alltext.split(":25:");
                        if (sArray1.length > 1 && sArray1[1].startsWith(actNum)) {
                            String spliter = "\n";
                            if (sArray1[1].contains("\r\n")) {
                                spliter  = "\r\n";
                            }
                            //获取openingBalance
                            String[] openingBal1 = sArray1[1].split(":60F:");
                            if (openingBal1.length > 1) {

                                String openingBal2 = (openingBal1[1].split(spliter))[0];
                                //金额
                                String startBalance = openingBal2.substring(10);
                                String cur = openingBal2.substring(7, 10);
                                startBalance = convertCommaToPoint(startBalance);
                                //若为D前面增加－
                                if ("D".equals(openingBal2.substring(0, 1))) {
                                    startBalance = "-" + startBalance;
                                }
                                String[] txns = sArray1[1].split(":61:");
                                if (txns.length > 1) {
                                    for (int i = 1; i < txns.length; i++) {
                                        RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                        String msg61 = txns[i];
                                        String valueDateStr = msg61.substring(0, 6);
                                        Date valueDate = Format.Date6Format.parse(valueDateStr);
                                        String transDateStr = msg61.substring(6, 10);
                                        tmpRetDetail.cur = convertCurToATS(cur);
                                        tmpRetDetail.actArea = actArea;
                                        tmpRetDetail.actNum = actNum;
                                        tmpRetDetail.valueDate = Format.Date10Format.format(valueDate);
                                        valueDate.setMonth(Integer.parseInt(transDateStr.substring(0, 2)) - 1);
                                        valueDate.setDate(Integer.parseInt(transDateStr.substring(2, 4)));
                                        tmpRetDetail.tranDate = Format.Date10Format.format(valueDate);
                                        tmpRetDetail.tranTime = Format.DateTimeFormat.format(valueDate);

                                        String cdFlag = "";
                                        String cdflag = msg61.substring(10, 11);
                                        int amtStart = 12;
                                        if ("D".equals(cdflag)) {
                                            cdFlag = "1";
                                        } else if ("C".equals(cdflag)) {
                                            cdFlag = "2";
                                        } else {
                                            cdflag = msg61.substring(10, 12);
                                            if ("RD".equals(cdflag)) {
                                                cdFlag = "2";
                                            } else {
                                                cdFlag = "1";
                                            }
                                            amtStart++;
                                        }
                                        tmpRetDetail.cdFlag = cdFlag;
                                        //计算当前余额
                                        //获取金额
                                        String trAmount = msg61.substring(amtStart, msg61.indexOf(",") + 3);
                                        trAmount = convertCommaToPoint(trAmount);
                                        BigDecimal amount = new BigDecimal(trAmount);
                                        BigDecimal openingbalance = new BigDecimal(startBalance);
                                        //openingbalance已经包含正负.
                                        if ("1".equals(cdFlag)) {
                                            //保留两位小数位
                                            startBalance = df.format(openingbalance.subtract(amount));
                                            //保留两位小数位
                                        } else {
                                            startBalance = df.format(openingbalance.add(amount));
                                        }
                                        //交易金额
                                        tmpRetDetail.tranAmt = df.format(amount);
                                        //账户余额
                                        tmpRetDetail.accBal = startBalance;
                                        String[] detailMsg = msg61.split(":86:");
                                        String msg61detail = detailMsg[0];
                                        String usage = "";
                                        for(String line : msg61detail.split(spliter)){
                                            if(line.startsWith("/PYTP/")){
                                                usage = line.substring(6).trim();
                                            }else if (line.startsWith("YBT")) {
                                                usage = line.trim();
                                            }
                                        }
                                        //批次号
                                        String batNo = "";
                                        //付款明细
                                        String comment = "";
                                        String payname = "";
                                        String recname = "";
                                        String returnReason = "";
                                        String asknumber= msg61.substring(msg61.indexOf(",") + 7, msg61.indexOf("//")).trim();
                                        if (detailMsg.length > 1) {
                                            String msg86detail = detailMsg[1];
                                            boolean YBTFlag = false;
                                            if (msg86detail.startsWith("YBT")) {
                                                YBTFlag = true;
                                            }
                                            if (YBTFlag) {
                                                String[] line = msg86detail.split(spliter);
                                                comment = line[1];
                                                recname = line[1].substring(0, line[1].indexOf(" "));
                                            } else {
                                                String[] lines = msg86detail.split(spliter);
                                                for (int x = 0; x < lines.length; x++) {
                                                    String line = lines[x];
                                                    //xue
                                                    if (line.startsWith("/CREF/")) {///AC/ 1001244319023106946
                                                        batNo = line.substring(6).trim();
                                                    } else if (line.startsWith("/REMI/")) {
                                                        StringBuilder sb = new StringBuilder(line.substring(6));
                                                        if (x + 1 < lines.length && !lines[x + 1].startsWith("/")) {
                                                            sb.append(lines[x + 1]);
                                                            x++;
                                                        }
                                                        comment = sb.toString();
                                                    } else if (line.startsWith("/ORDP/")) {
                                                        payname = line.substring(6).trim();
                                                    } else if (line.startsWith("/BENM/")) {
                                                        //存在两行可能
                                                        // :86:/OR/140903YLP17026351
                                                        ///AC/12345678901234567890
                                                        ///BENM/收款方名称收款方名称收款方
                                                        //名称收款方名称收款方名称收款方名
                                                        ///REMI/付款明明细付款明明细付款明
                                                        //明细付款明明细付款明明细付款明明
                                                        StringBuilder sb = new StringBuilder(line.substring(6));
                                                        if (x + 1 < lines.length && !lines[x + 1].startsWith("/")) {
                                                            sb.append(lines[x + 1]);
                                                            x++;
                                                        }
                                                        recname = sb.toString();
                                                    } else if (line.startsWith("/RJCT/")) {
                                                        returnReason = line.substring(6).trim();
                                                    }
                                                }
                                            }
                                        }
                                        if (comment.contains("+")) {
                                            String[] abstr = comment.split("\\+",-1);
                                            if (abstr.length > 2) {
                                                tmpRetDetail.abstr = abstr[1];
                                            }
                                        }
                                        if(!"".equals(returnReason)){
                                            comment = comment + "+" + returnReason;
                                        }
                                        tmpRetDetail.reqBatchNO = batNo;
                                        tmpRetDetail.comment = comment;
                                        tmpRetDetail.usage = usage;
                                        tmpRetDetail.recAccName = recname;
                                        tmpRetDetail.askNumber = asknumber;
                                        if("".equals(tmpRetDetail.recAccName)){
                                            tmpRetDetail.recAccName = payname;
                                        }
                                        retAts.writeRetDetail(tmpRetDetail);
                                    }
                                }
                            }
                        }
                    } catch (Exception ex) {
                        WriteBankLogLn("解析：" + aimFile + " 文件异常：\r\n" + ex.getMessage());
                    }

                }

            } catch (Exception ex) {
                WriteBankLogLn(ex);
                //执行状态
                if (!retAts.hasWrittenRespCode) {
                    retAts.writeRespCode("-1");
                }
                //执行结果描述
                if (!retAts.hasWrittenRespInfo) {
                    retAts.writeRespInfo("历史明细查询异常。");
                }
                retAts.writeEnd();
                return retAts;
            }
            if (!retAts.hasWrittenRespCode) {
                retAts.writeRespCode("0");
            }
            if (!retAts.hasWrittenRespInfo) {
                retAts.writeRespInfo("查询成功。");
            }
            retAts.writeEnd();
        }else {
            //查询时间校验
            String[] dateAry=getQueryDate(p_req7516.dateFrom,p_req7516.dateTo);
            p_req7516.dateFrom=dateAry[0];
            p_req7516.dateTo=dateAry[1];

            String accountNum = p_req7516.actNum;
            Date dateStart = Format.Date8Format.parse(p_req7516.dateFrom);
            Date dateEnd = Format.Date8Format.parse(p_req7516.dateTo);
            Calendar calendar = Calendar.getInstance();
            while (!dateStart.after(dateEnd)){
                String dealedPath = getBankConfig().getValueAsString("DealedPath")+File.separator+
                        Format.Date8Format.format(dateStart)+File.separator+"MT940"+File.separator+
                        accountNum+"_7516.txt";
                if(!FileHelper.existFile(dealedPath)){
                    calendar.setTime(dateStart);
                    calendar.add(Calendar.DAY_OF_MONTH, 1);
                    dateStart = calendar.getTime();
                    continue;
                }
                String readLine = "";
                InputStreamReader isr = new InputStreamReader(new FileInputStream(dealedPath), "UTF-8");
                BufferedReader reader = new BufferedReader(isr);
                while ((readLine=reader.readLine())!=null) {
                    //账号 | 币种 | 交易日期| 交易时间| 计息日期 | 交易金额 |借贷标识| 账户余额 |对方账号|
//                    对方户名 | 对方银行 |用途|
                    String[] transDetail = readLine.split("\\|");
                    RetAtsTransDetail retDetail = new RetAtsTransDetail();
                    retDetail.actArea=p_req7516.actArea;
                    retDetail.actNum = transDetail[0].trim();
                    retDetail.cur =convertCurToATS(transDetail[1].trim());
                    retDetail.tranDate = transDetail[2].trim();
                    retDetail.tranTime = transDetail[3].trim();
                    retDetail.valueDate = transDetail[4].trim();
                    retDetail.tranAmt = transDetail[5].trim();
                    retDetail.cdFlag = "C".equals(transDetail[6].trim())?"2":"1";
                    retDetail.recAccNum = transDetail[8].trim();
                    retDetail.accBal = transDetail[7].trim();
                    retDetail.recAccName = transDetail[9].trim();
                    retDetail.recAccBank = transDetail[10].trim();
                    String[] transArray=transDetail[11].split("##");
                    if(transArray.length>1){
                        if(transArray[0].trim().length()>256){
                            retDetail.usage = transArray[0].trim().substring(0,256);
                            retDetail.comment = transArray[0].trim().substring(256)+" "+transArray[1];
                        }else {
                            retDetail.usage = transArray[0].trim();
                            retDetail.comment = transArray[1];
                        }
                    }else {
                        if(transArray[0].trim().length()>256){
                            retDetail.usage = transArray[0].trim().substring(0,256);
                            retDetail.comment = transArray[0].trim().substring(256);
                        }else {
                            retDetail.usage = transArray[0].trim();
                        }
                    }
                    retDetail.askNumber=transDetail.length>11?transDetail[12].trim():"";
                    retAts.writeRetDetail(retDetail);
                }
                reader.close();
                calendar.setTime(dateStart);
                calendar.add(Calendar.DAY_OF_MONTH, 1);
                dateStart = calendar.getTime();
            }
            retAts.writeEnd();
        }
        return retAts;
    }

    @Override
    public RetAtsTrans d_7515_TodayTrans(Req7515TodayTrans p_req7515) throws Exception {
        //BankCode TransType TransSeqID
        RetAtsTrans retAts = new RetAtsTrans(p_req7515.reqHeader);
        //写返回ATS的统一头部信息
        retAts.writeStart();
        //保险
        if("0".equals(this.getBankConfig().getValueAsString("channelFalg"))){
            // String transTime = _ClientReqDoc.SelectSingleNode("descendant::TransTime").InnerText;
            String actNum = p_req7515.actNum;
            try {
                //账号地区区域码
                String actArea = p_req7515.actArea;
                //币种
                String actCur = p_req7515.actCur;
                //下载结果文件
                downloadFile();
                String datePath = getReceivePath(EnumDirType.MT942.getValue(), new Date());
               //String datePath = getReceivePath("MT942", new Date());
                //被筛选文件
                List<String> allDetailsFileNames = getDirectoryAllFileName(datePath);
                //筛选结果文件
                List<String> detailsFileNames = new ArrayList<String>();
                List<RetAtsTransDetail> retDetails = new ArrayList<RetAtsTransDetail>();
                for (String fileName : allDetailsFileNames) {
                    //MT942CN.EJ321.071910135852.088251418011.TXT
                    if (fileName.split("\\.")[3].equals(actNum)) {
                        detailsFileNames.add(fileName);
                    }
                }
                for (String fileName : detailsFileNames) {
                    try {
                        String alltext = "";
                        synchronized (this) {
                            //读取文件内容
                            alltext = FileHelper.readFileText(getTrimPath(datePath) + File.separator + fileName, getCharset());
                        }
                        //对单个文件进行解析查找对应的账号明细信息 //"H", 明细头记录拆分符
                        String[] sArray1 = alltext.split(":25:");
                        if (sArray1.length > 1 && sArray1[1].startsWith(actNum)) {
                            String[] txns = sArray1[1].split(":61:");
                            if (txns.length > 1) {
                                String spliter = "\n";
                                if (sArray1[1].contains("\r\n")) {
                                    spliter  = "\r\n";
                                }
                                for (int i = 1; i < txns.length; i++) {
                                    RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                    String msg61 = txns[i];
                                    String valueDateStr = msg61.substring(0, 6);
                                    Date valueDate = Format.Date6Format.parse(valueDateStr);
                                    String transDateStr = msg61.substring(6, 10);
                                    tmpRetDetail.actArea = actArea;
                                    tmpRetDetail.actNum = actNum;
                                    tmpRetDetail.valueDate = Format.Date10Format.format(valueDate);
                                    valueDate.setMonth(Integer.parseInt(transDateStr.substring(0, 2)) - 1);
                                    valueDate.setDate(Integer.parseInt(transDateStr.substring(2, 4)));
                                    tmpRetDetail.tranDate = Format.Date10Format.format(valueDate);
                                    tmpRetDetail.tranTime = Format.DateTimeFormat.format(valueDate);
//                                tmpRetDetail.recAccName = recName;
                                    //region 确定借贷标志 Debit / Credit Flag （1:支出、2:收入）
                                    String cdFlag = "";
                                    String cdflag = msg61.substring(10, 11);
                                    int amtStart = 12;
                                    if ("D".equals(cdflag)) {
                                        cdFlag = "1";
                                    } else if ("C".equals(cdflag)) {
                                        cdFlag = "2";
                                    } else {
                                        cdflag = msg61.substring(10, 12);
                                        if ("RD".equals(cdflag)) {
                                            cdFlag = "2";
                                        } else {
                                            cdFlag = "1";
                                        }
                                        amtStart++;
                                    }
                                    tmpRetDetail.cdFlag = cdFlag;
                                    //计算当前余额
                                    //获取金额
                                    String trAmount = msg61.substring(amtStart, msg61.indexOf(",") + 3);
                                    trAmount = convertCommaToPoint(trAmount);
                                    BigDecimal amount = new BigDecimal(trAmount);
                                    //交易金额
                                    tmpRetDetail.tranAmt = df.format(amount);
//                                    //用途 BAI CODE
//                                    tmpRetDetail.usage = msg61.substring(msg61.indexOf(",") + 4, msg61.indexOf(",") + 7);
                                    //detail.Abstr;对账码 批次号
                                     String asknumber= msg61.substring(msg61.indexOf(",") + 7, msg61.indexOf("//")).trim();
                                    String[] detailMsg = msg61.split(":86:");
                                    String msg61detail = detailMsg[0];
                                    String usage = "";
                                    for(String line : msg61detail.split(spliter)){
                                        if(line.startsWith("/PYTP/")){
                                            usage = line.substring(6).trim();
                                        }else if (line.startsWith("YBT")) {
                                            usage = line.trim();
                                        }
                                    }
                                    //批次号
                                    String batNo = "";
                                    //付款明细
                                    String comment = "";
                                    String payname = "";
                                    String recname = "";
                                    String returnReason = "";
                                    if (detailMsg.length > 1) {
                                        String msg86detail = detailMsg[1];
                                        boolean YBTFlag = false;
                                        if (msg86detail.startsWith("YBT")) {
                                            YBTFlag = true;
                                        }
                                        if (YBTFlag) {
                                            String[] line = msg86detail.split(spliter);
                                            comment = line[1];
                                            recname = line[1].substring(0, line[1].indexOf(" "));
                                        } else {
                                            String[] lines = msg86detail.split(spliter);
                                            for (int x = 0; x < lines.length; x++) {
                                                String line = lines[x];
                                                if (line.startsWith("/CREF/")) {
                                                    batNo = line.substring(6).trim();
                                                    //xue
                                                } else if (line.startsWith("/REMI/")) {
                                                    StringBuilder sb = new StringBuilder(line.substring(6));
                                                    if (x + 1 < lines.length && !lines[x + 1].startsWith("/")) {
                                                        sb.append(lines[x + 1]);
                                                        x++;
                                                    }
                                                    comment = sb.toString();
                                                } else if (line.startsWith("/ORDP/")) {
                                                    payname = line.substring(6).trim();
                                                } else if (line.startsWith("/BENM/")) {
                                                    //存在两行可能
                                                    // :86:/OR/140903YLP17026351
                                                    ///AC/12345678901234567890
                                                    ///BENM/收款方名称收款方名称收款方
                                                    //名称收款方名称收款方名称收款方名
                                                    ///REMI/付款明明细付款明明细付款明
                                                    //明细付款明明细付款明明细付款明明
                                                    StringBuilder sb = new StringBuilder(line.substring(6));
                                                    if (x + 1 < lines.length && !lines[x + 1].startsWith("/")) {
                                                        sb.append(lines[x + 1]);
                                                        x++;
                                                    }
                                                    recname = sb.toString();
                                                } else if (line.startsWith("/RJCT/")) {
                                                    returnReason = line.substring(6).trim();
                                                }
                                            }
                                            //tmpRetDetail.reqBatchNO = detailMsg[1].substring();
                                        }
                                    }


                                    if (comment.contains("+")) {
                                        String[] abstr = comment.split("\\+",-1);
                                        if (abstr.length > 2) {
                                            tmpRetDetail.abstr = abstr[1];
                                        }
                                    }
                                    if(!"".equals(returnReason)){
                                        comment = comment + "+" + returnReason;
                                    }
                                    tmpRetDetail.reqBatchNO = batNo;
                                    tmpRetDetail.comment = comment;
                                    tmpRetDetail.usage = usage;
                                    tmpRetDetail.recAccName = recname;
                                    tmpRetDetail.askNumber = asknumber;
                                    if("".equals(tmpRetDetail.recAccName)){
                                        tmpRetDetail.recAccName = payname;
                                    }
                                    //账户余额
                                    tmpRetDetail.accBal = "";
                                    retDetails.add(tmpRetDetail);
                                }
                            }
                        }
                    } catch (Exception ex) {
                        WriteBankLogLn("解析：" + fileName + " 文件异常：" + ex);
                    }

                }
                for (RetAtsTransDetail retDetail : retDetails) {
                    retAts.writeRetDetail(retDetail);
                }
            } catch (Exception ex) {
                if (!retAts.hasWrittenRespCode) {
                    retAts.writeRespCode("-1");
                }
                WriteBankLogLn("产生异常" + ex);
                if (!retAts.hasWrittenRespInfo) {
                    retAts.writeRespInfo("产生异常" + ex);
                }
                //执行结果描述
                retAts.writeEnd();
                return retAts;
            }
            //执行状态
            if (!retAts.hasWrittenRespCode) {
                retAts.writeRespCode("0");
            }
            //执行结果描述
            if (!retAts.hasWrittenRespInfo) {
                retAts.writeRespInfo("成功");
            }
            retAts.writeEnd();
        }else {
            String accNum = p_req7515.actNum;
            String date =Format.Date8Format.format(new Date());
            String dealedPath = getBankConfig().getValueAsString("DealedPath")+File.separator+date+
                    File.separator+"MT942"+File.separator+accNum+"_7515.txt";
            if(FileHelper.existFile(dealedPath)){
                InputStreamReader isr = new InputStreamReader(new FileInputStream(dealedPath), "UTF-8");
                BufferedReader reader = new BufferedReader(isr);
                String readLine ="";
                while ((readLine=reader.readLine())!=null){
                    // 账号 | 币种 | 交易日期| 交易时间| 计息日期 | 交易金额 |借贷标识| 账户余额 |对方账号|
                    // 对方户名 | 对方银行 |用途 |支付流水号
                    String[] transDetail = readLine.split("\\|");
                    RetAtsTransDetail detail = new RetAtsTransDetail();
                    detail.actArea=p_req7515.actArea;
                    detail.actNum = transDetail[0].trim();
                    detail.cur =convertCurToATS(transDetail[1].trim());
                    detail.tranDate =transDetail[2].trim();
                    detail.tranTime = transDetail[3].trim();
                    detail.valueDate = transDetail[4].trim();
                    detail.tranAmt = transDetail[5].trim();
                    detail.cdFlag = "C".equals(transDetail[6].trim())?"2":"1";
                    detail.accBal =transDetail[7].trim();
                    detail.recAccNum =transDetail[8].trim();
                    detail.recAccBank = transDetail[10].trim();
                    detail.recAccName = transDetail[9].trim();
                    String[] transArray=transDetail[11].split("##");
                    if(transArray.length>1){
                        if(transArray[0].trim().length()>256){
                            detail.usage = transArray[0].trim().substring(0,256);
                            detail.comment = transArray[0].trim().substring(256)+" "+transArray[1];
                        }else {
                            detail.usage = transArray[0].trim();
                            detail.comment = transArray[1];
                        }
                    }else {
                        if(transArray[0].trim().length()>256){
                            detail.usage = transArray[0].trim().substring(0,256);
                            detail.comment = transArray[0].trim().substring(256);
                        }else {
                            detail.usage = transArray[0].trim();
                        }
                    }
                    detail.askNumber=transDetail.length>11?transDetail[12].trim():"";
                    retAts.writeRetDetail(detail);
                }
                reader.close();
            }else{
                retAts.writeRespCode("0");
                retAts.writeRespInfo("今日明细银行还没返回,请稍后再查");
            }
            retAts.writeEnd();
        }
        return retAts;
    }
}
